package com.common.link.controller;

import cn.hutool.core.util.StrUtil;
import com.common.link.model.EntityVO;
import com.common.link.model.RelationVO;
import com.common.link.config.LinkConfig;
import com.common.link.service.RemoteAtlasService;
import com.common.model.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 描述：
 *
 * @author xianggj
 * @Date 2022/2/18 11:31
 **/
@Slf4j
@RestController
@RequestMapping("/atlas")
@Api(tags = "图谱实体-关系类型")
public class AtlasController {

    @Autowired
    private RemoteAtlasService remoteAtlasService;

    /**
     * 查询标注用户列表
     */
    @ApiOperation(value = "查询实体列表", notes = "前端自行假分页")
    @ApiImplicitParam(value = "查询关键字", name = "name", required = false)
    @GetMapping("/entityList")
    public Result entityList(@RequestParam(value = "name", required = false) String name, HttpServletRequest request) {
        String token = request.getHeader(LinkConfig.HEADER);
        //不用判断token 存不存在 因为过滤器已经做了
        List<EntityVO> entityList = remoteAtlasService.getEntityList(token);
        if (StrUtil.isNotBlank(name)){
            entityList = entityList.stream().filter(e->StrUtil.contains(e.getName(), name)).collect(Collectors.toList());
        }
        return Result.succeed(entityList, "查询成功");
    }

    /**
     * 查询标注用户列表
     */
    @ApiOperation(value = "查询关系列表", notes = "前端自行假分页")
    @ApiImplicitParam(value = "查询关键字", name = "name", required = false)
    @GetMapping("/relationList")
    public Result relationList(@RequestParam(value = "name", required = false) String name, HttpServletRequest request) {
        String token = request.getHeader(LinkConfig.HEADER);
        //不用判断token 存不存在 因为过滤器已经做了
        List<RelationVO> relationList = remoteAtlasService.getRelationList(token);
        if (StrUtil.isNotBlank(name)){
            relationList = relationList.stream().filter(e->StrUtil.contains(e.getName(), name)).collect(Collectors.toList());
        }
        return Result.succeed(relationList, "查询成功");
    }


}
